home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / terminal / top_152 / src152.exe / rar / TOPSTR.PAS < prev    next >
Pascal/Delphi Source File  |  1995-05-16  |  6KB  |  246 lines

  1. {┌─────────────────────────────────────────────────────────────────────────┐}
  2. {│                                                                         │}
  3. {│                              T. O. P.                                   │}
  4. {│                                                                         │}
  5. {│                        (T)he  (O)ther  (P)acket                         │}
  6. {│                                                                         │}
  7. {│ T O P S T R . P A S                                                     │}
  8. {│                                                                         │}
  9. {│                                                                         │}
  10. {│ Library - Unit mit oft benötigten Routinen für die Stringverarbeitung   │}
  11. {└─────────────────────────────────────────────────────────────────────────┘}
  12.  
  13. Function  str_int (* Zeile : Str10 : LongInt *);
  14. Var i    : Integer;
  15.     Zahl : LongInt;
  16. Begin
  17.   Val(Zeile,Zahl,i);
  18.   if (i > 0) then Zahl := 0;
  19.   Str_Int := Zahl;
  20. End;
  21.  
  22.  
  23. Function  int_str (* i : LongInt) : Str10 *);
  24. Var   Hstr  : String[10];
  25. Begin
  26.   str(i,Hstr);
  27.   int_str := Hstr;
  28. End;
  29.  
  30.  
  31. Function ConstStr (* VC : Char ; L : Byte) : Str80; *);
  32. Const  ML = 80;
  33. Var    Bstr : String[80];
  34. Begin
  35.   if L > ML then L := ML;
  36.   Bstr := '';
  37.   FillChar(Bstr[1],L,VC);
  38.   Bstr[0] := Chr(L);
  39.   ConstStr := Bstr;
  40. End;
  41.  
  42.  
  43. Function RetStr (* Zeile : String) : String *) ;
  44. Var   i : Byte;
  45. Begin
  46.  i := pos(M1,Zeile);
  47.  if i = 0 then i := Length(Zeile)
  48.           else Dec(i);
  49.  Zeile[0] := Chr(i);
  50.  RetStr := Zeile;
  51. End;
  52.  
  53.  
  54. Function CutStr (* Zeile : String) : String *) ;
  55. Var   i : Byte;
  56. Begin
  57.  i := pos(B1,Zeile);
  58.  if i = 0 then i := Length(Zeile)
  59.           else Dec(i);
  60.  Zeile[0] := Chr(i);
  61.  CutStr := Zeile;
  62. End;
  63.  
  64.  
  65. Function  RestStr (* (Zeile : String) : String *);
  66. Var       i,i1 : Byte;
  67. Begin
  68.   i := pos(B1,Zeile);
  69.   if i > 0 then
  70.   begin
  71.     i1 := length(Zeile) - i;
  72.     Zeile[0] := Chr(i1);
  73.     move(Zeile[i+1],Zeile[1],i1);
  74.     While (Zeile[0] > #0) and (Zeile[1] = ' ') do delete(Zeile,1,1);
  75.   end else Zeile := '';
  76.   RestStr := Zeile;
  77. End;
  78.  
  79.  
  80. Function UpCaseStr (* (Zeile : String) : String *) ;
  81. Var  i   : Byte;
  82. Begin
  83.   for i := 1 to Ord(Zeile[0]) do
  84.    if Zeile[i] in ['a'..'z'] then dec(Zeile[i],$20);
  85.   UpCaseStr := Zeile;
  86. End;
  87.  
  88.  
  89. Procedure KillEndBlanks (* var Zeile : String *);
  90. Begin
  91.   While (Zeile[0] > #0) and (Zeile[Ord(Zeile[0])] = B1) do dec(Zeile[0]);
  92. End;
  93.  
  94.  
  95. Procedure KillStartBlanks (* Var Zeile : String *);
  96. Begin
  97.   While (Zeile[0] > #0) and (Zeile[1] = B1) do
  98.   begin
  99.     dec(Zeile[0]);
  100.     move(Zeile[2],Zeile[1],Ord(Zeile[0]));
  101.   end;
  102. End;
  103.  
  104.  
  105. Function ParmStr (* (Nr : Byte; VC : char; Zeile : String) : String *);
  106. Var      i,i1,
  107.          i2,i3 : Byte;
  108.          Hstr  : String;
  109. Begin
  110.   if Zeile > '' then
  111.   begin
  112.     i2 := 0;
  113.     i3 := 254;
  114.     While (ord(Zeile[0]) > 0) and (Zeile[1] = VC) do
  115.     begin
  116.       delete(Zeile,1,1);
  117.       inc(i2);
  118.     end;
  119.  
  120.     Hstr := '';
  121.     i1 := 1;
  122.     for i := 1 to Ord(Zeile[0]) do
  123.     begin
  124.       if Nr = i1 then if Zeile[i] <> VC then
  125.       begin
  126.         Hstr := Hstr + Zeile[i];
  127.         i3 := i;
  128.       end;
  129.       if (Zeile[i] = VC) and (Zeile[i-1] <> VC) then inc(i1);
  130.     end;
  131.     While (Hstr[0] > #0) and (Hstr[Ord(Hstr[0])] = B1) do Hstr[0] := Chr(Ord(Hstr[0])-1);
  132.     While (Hstr[0] > #0) and (Hstr[1] = B1) do delete(Hstr,1,1);
  133.     ParmAnz := i1;
  134.     ParmPos := Byte(i3 + i2 - length(Hstr) + 1);
  135.     ParmStr := Hstr;
  136.   end else
  137.   begin
  138.     ParmAnz := 0;
  139.     ParmPos := 0;
  140.     ParmStr := '';
  141.   end;
  142. End;
  143.  
  144.  
  145. Function  SFillStr (* Anz : Byte; VC : Char; Zeile : String) : String *);
  146. Var  i,i1 : Byte;
  147. Begin
  148.   i := length(Zeile);
  149.   if i < Anz then
  150.   begin
  151.     i1 := Anz - i;
  152.     move(Zeile[1],Zeile[i1+1],i);
  153.     FillChar(Zeile[1],i1,VC);
  154.     Zeile[0] := Chr(Anz);
  155.   end;
  156.   SFillStr := Zeile;
  157. End;
  158.  
  159.  
  160. Function  EFillStr (* Anz : Byte; VC : Char; Zeile : String) : String *);
  161. Var  i : Byte;
  162. Begin
  163.   i := length(Zeile);
  164.   if i < Anz then
  165.   begin
  166.     FillChar(Zeile[i+1],Anz-i,VC);
  167.     Zeile[0] := Chr(Anz);
  168.   end;
  169.   EFillStr := Zeile;
  170. End;
  171.  
  172.  
  173. Function  ZFillStr (* Anz : Byte; VC : Char; Zeile : String) : String *);
  174. Begin
  175.   While length(Zeile) < Anz do Zeile := VC + Zeile + VC;
  176.   if length(Zeile) > Anz then Zeile := copy(Zeile,1,Anz);
  177.   ZFillStr := Zeile;
  178. End;
  179.  
  180.  
  181. Function  Hex (* Dezimal : LongInt; Stellenzahl : Byte) : Str8 *);
  182. Const HexChars  : Array [0..15] of Char = ('0','1','2','3','4','5','6','7',
  183.                                            '8','9','A','B','C','D','E','F');
  184. Var    Stelle : Byte;
  185. Begin
  186.   if (Stellenzahl > 8) then Stellenzahl := 8;
  187.   Hex := '        ';
  188.   Hex[0] := Chr(Stellenzahl);
  189.   for Stelle := Stellenzahl downto 1 do
  190.   begin
  191.     Hex[Stelle] := HexChars[Dezimal and $0F];
  192.     Dezimal := Dezimal shr 4;
  193.   end;
  194. End;
  195.  
  196.  
  197. Function  Adr_absolut(Zeiger : Pointer) : LongInt;
  198. Begin
  199.   if Zeiger = NIL then Adr_absolut := 0
  200.          else Adr_absolut := (LongInt(Seg(Zeiger^)) shl 4) + Ofs(Zeiger^);
  201. End;
  202.  
  203.  
  204. Function Pointer_Str (* Zeiger : Pointer) : Str9 *);
  205. Begin
  206.   if Zeiger = NIL then Pointer_Str := 'NIL      '
  207.          else Pointer_Str := Hex(Seg(Zeiger^),4) + DP + Hex(Ofs(Zeiger^),4);
  208. End;
  209.  
  210.  
  211. Function FormByte (* Zeile : str11) : str11  *);
  212. var  Bstr : String[11];
  213.      i,i1 : Byte;
  214. Begin
  215.   Bstr := '';
  216.   i1 := length(Zeile);
  217.   for i := 1 to i1 do
  218.   begin
  219.     Bstr := Zeile[i1+1-i] + Bstr;
  220.     if (i > 1) and (i < i1) and (i mod 3 = 0) then Bstr := Pkt  + Bstr;
  221.   end;
  222.   FormByte := Bstr;
  223. End;
  224.  
  225.  
  226. Function  Bin (* Dezimal : LongInt ; Stellenzahl : Byte) : Str32 *);
  227. Var    Stelle : Byte;
  228. Begin
  229.   if Stellenzahl > 32 then Stellenzahl := 32;
  230.   Bin[0] := Chr(Stellenzahl);
  231.   for Stelle := Stellenzahl downto 1 do
  232.   begin
  233.     if (Dezimal and $01) > 0 then Bin[Stelle] := '1'
  234.                              else Bin[Stelle] := '0';
  235.     Dezimal := Dezimal shr 1;
  236.   end;
  237. End;
  238.  
  239.  
  240. Procedure Strip (* var Call: str9 *);
  241. Var p : Byte;
  242. Begin
  243.   p := pos('-',Call);
  244.   if p > 0 then Call := Copy(Call,1,p-1);
  245. End;
  246.